function Vue(options){
    this._init(options);
}
Vue.prototype._init=function(options){
    this._options=options;
    this._data=options.data;
    this._methods=options.methods;
    this._el=document.querySelector(options.el);
    this._binding={};
    this.observer(options.data);
    this._compile(this._el);
    this.observerMethod(options.methods);
    //this.deepLevel=0;
}
Vue.prototype.observer=function(object,keystr){
    for(key in object){
        if(object.hasOwnProperty(key)){
            if(key.split(".").length>2){
                throw new Exception("对象超过三层")
                break;
            }
            var tmpkeystr=(keystr?(keystr+"."):"")+key;
            var value=object[key];
             this._binding[tmpkeystr]={        //初始化与DOM绑定的数据对象
                    _directives:[]
             };

            if(typeof value ==="object"){
                this.observer(value,tmpkeystr);
            }
            this.defineReactive(object,key,value,tmpkeystr);
        }
    }
}
Vue.prototype.defineReactive= function(obj, key, val,keystr) {
    self=this;
    Object.defineProperty(obj,key,{
         enumerable:true,
         configurable:true,
         get:function(){
             return val;
         },
         set:function(newval){
             if(val===newval){
                 return;
             }
             val=newval;
                  self._binding[keystr]._directives.forEach(function(item){
                  console.log(item);
                item.update();
            })
         }
    })
 }
 //Vue.prototype.defineReactive=defineReactive;
   //遍历函数域，对绑定的函数进行改造
 Vue.prototype._parseFunc=function(attrVal){
        var args=/\(.*\)/.exec(attrVal);
        if(args) {              //如果函数带参数,将参数字符串转换为参数数组
            args=args[0];
            attrVal=attrVal.replace(args,"");
            args=args.replace(/[\(\)\'\"]/g,'').split(",");
        }
        else args=[];
        return {
            args:args,
            methodName:attrVal,
        };
    };
Vue.prototype.observerMethod=function(methodList){
     self=this;
     for(var key in methodList){
           let func=methodList[key];
           methodList[key]=(function(){
               return function(){
                   func.apply(self._data,arguments);
               }
           })();
     }
 }
  Vue.prototype._compile=function (root){
    var self=this;
    var nodes=root.children;
    for(var i=0;i<nodes.length;i++){
        var node=nodes[i];
        if(node.children.length>0)this._compile(node);
        if(node.hasAttribute("v-model")&&(node.tagName=="INPUT"||node.tagName=="TEXTAREA")){
            var attrVal=node.getAttribute("v-model");
            var vmodelin=new Directive(
                "input",
                node,
                self,
                attrVal,
                "value"
            )
            self._binding[attrVal]._directives.push(vmodelin);
            vmodelin.update();
            node.addEventListener("input",(function(key){
                 var attrVal=node.getAttribute("v-model");
                 return function(){
                     setDeepObjectAttribute(self._data,attrVal,nodes[key].value)
                     //var tmpobj=deepObjectValue(self._data,attrVal);
                    //tmpobj=nodes[key].value;
                     //self._data[attrVal]=nodes[key].value;
                 }
            })(i));
        }
        if(node.hasAttribute("v-bind")){
             var attrVal=node.getAttribute("v-bind");
             var vbindin=new Directive(
                        "text",
                        node,
                        self,
                        attrVal,
                        "innerHTML"
                );
            self._binding[attrVal]._directives.push(vbindin);                
            vbindin.update();
        }
        if(node.hasAttribute("v-click")){
            var attrVal=nodes[i].getAttribute("v-click");
            mehtodsa=self._parseFunc(attrVal);
            var method= self._methods[mehtodsa.methodName]
            node.onclick=(function(){
                 return function(){
                     method.apply(self._data,mehtodsa.args);
                 }
                      
                  
            })();
        }
    }
 }
// Vue.prototype._compile=compile;
 function Directive(name,el,vm,exp,attr){
    this.name=name;         //指令名称，例如文本节点，该值设为"text"
    this.el=el;             //指令对应的DOM元素
    this.vm=vm;             //指令所属Lue实例
    this.exp=exp;           //指令对应的值，本例如"count"
    this.attr=attr;         //绑定的属性值，本例为"innerHTML"
   // this.update();          //首次绑定时更新

}
Directive.prototype.update=function(){
    //更新DOM节点的预设属性值
    this.el[this.attr]=deepObjectValue(this.vm._data,this.exp);
};
function deepObjectValue(object,dotStr){
    if(dotStr.indexOf(".")<0){
        return object[dotStr];
    }else{
        var dotlist=dotStr.split(".");
        var tmpobj=object;
        var tmplength=3
        if(dotlist.length<3){
            tmplength=dotlist.length;
        }
        for (var ijk=0;ijk<tmplength;ijk++) {
            tmpobj=tmpobj[dotlist[ijk]];
        }
        return tmpobj;
    }
}
function setDeepObjectAttribute(object,dotStr,value){
    if(dotStr.indexOf(".")<0){
         object[dotStr]=value;
    }else{
        var dotlist=dotStr.split(".");
        var tmpobj=object;
        var tmplength=3
        if(dotlist.length<3){
            tmplength=dotlist.length;
        }
        for (var ijk=0;ijk<tmplength;ijk++) {
            var lsestr=dotlist[ijk];
            if(ijk==tmplength-1){
                tmpobj[lsestr]=value;
                break;
            }
            tmpobj=tmpobj[lsestr];
        }
        return tmpobj;
    }
}
// http://XXX/auth.jsp?serviceid=com.xbstar.leader&state=1111&authtype=redict_uri
// http://222.76.19.210:8089/index.jsp&state=111&scope="eeerererererewqeeweewe"


// {
//     scope:"xxxx",
//     state:"111",
//     serviceobject:'xxxx'
// }


// scope={
//     openid:"eeeeeeeeeeeeeewww",
//     timestamp:"23222222",
//     ticket:"qwqwwwewewwewewe"
// }


// servceobjects=[{
//     servicename:"中科西北星养老3.0",
//     domain:"http://192.168.1.21",
//     serviceid:"com.xbstar.nurhomev3"
// }]